package Model.Util;

import java.sql.ResultSet;
import java.sql.SQLException;

import Model.Bean.Phone;
import Model.DbAccess.DbConnection;

public class AdminModel {
	
	DbConnection db = new DbConnection();
	
	/*
	 * Admin login
	 */
	public boolean Login(String adminID, String password) throws SQLException 
	{
		
		String sql = "Select * from tbAdmin where AdminID = ? and [Password] = ?";
		
		String[] params = new String[] {
			adminID, password	
		};
		
		ResultSet rs = db.executeQuery(sql, params);
		
		if(rs.next()) {
			return true;
		}
		
		return false;
	}
	
	
	/*
	 * Add New Phone
	 */
	public boolean AddPhone(Phone phone)
	{
		String sql = "Insert into * values(?,?,?,?)";
		
		Object[] params = new Object[] {
				phone.getPhoneName(),
				phone.getPhoneType(),
				phone.getDescription(),
				phone.getPrice()
			};
		
		boolean rs = db.executeUpdate(sql, params);
		
		return rs;
	}
	
	
	/*
	 * Edit Phone
	 */
	public boolean EditPhone(Phone phone)
	{
		String sql = "Update Phone " +
				"Set PhoneName = " + phone.getPhoneName() +
				", PhoneType = " + phone.getPhoneType() + 
				", Description = " + phone.getDescription() +
				", Price = " + phone.getPrice() +
				" Where PhoneID = " + phone.getPhoneID();
		
		Object[] params = new Object[] {
				phone.getPhoneName(),
				phone.getPhoneType(),
				phone.getDescription(),
				phone.getPrice()
			};
		
		boolean rs = db.executeUpdate(sql, params);
		
		return rs;
	}
	
	
	/*
	 * Delete Phone
	 */
	public boolean DeletePhone(int phoneID) {
		
		String sql = "Delete Phone where PhoneID = ?";
		
		Object[] params = new Object[] {
				phoneID
			};
		
		boolean rs = db.executeUpdate(sql, params);
		
		return rs;
	}
}
